package com.yunhe.sms.control;

import com.yunhe.sms.dao.UserDao;
import com.yunhe.sms.mode.User;
import com.yunhe.sms.view.Login;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2017/8/7 0007.
 */
public class LoginController {
    private static  User currUser;   //表示当前登录用户
    public static void loginRoute(int type){
        String[] str = Login.loginUI();
        int i = login(str[0],str[1],type);
        switch (i){
            case 0:{
                System.out.println("登录失败");
               IndexController.router();
                break;
            }
            case 1:HomeControllerFactory.homeRoute(type);break;
        }
    }

    public static int login(String userName,String password,int type){
        int rsCode =0;
        User user = UserDao.getOneUser(userName, password, type);
        if ( null!=user){
            System.out.println("登录成功！");
            rsCode = 1;
            currUser = user;
        }
        return rsCode;
    }

    /**
     *
     */
    public static void logout(){
        System.out.println("退出登录！");
        currUser = null;
        IndexController.router();
    }

    /**
     *
     * @return
     */
    public static User getCurrUser() {
        return currUser;
    }
}
